﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionsLib.Dictionary
{
    public static class DictionaryExtensionsToString
    {


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="self"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string ToString<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, string format)
        {
            if (dictionary != null)
            {
                if (dictionary.Count != 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (KeyValuePair<TKey, TValue> pair in dictionary)
                    {
                        sb.AppendFormat(format, pair.Key, pair.Value);
                    }
                    return sb.ToString();
                }
                else
                {
                    return "[empty]";
                }
            }
            else
            {
                return "[null]";
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string ToString<TKey, TValue>(this IDictionary<TKey, TValue> data)
        {
            return data.ToString<TKey, TValue>("{0}={1} \r\n");
        }




    }
}
